/*
 * @Author: czy
 * @Date: 2021-04-24 08:16:01
 * @LastEditTime: 2021-05-04 08:47:32
 */
#include "mystdio.h"
#include "mystring.h"
#include "mytime.h"
#include "exception.h"
#include "i8259A.h"

/**
 * @description: Interrupt switch on.
 */
void enable_interrupt(void);

/**
 * @description: Interrupt switch off.
 */
void disable_interrupt(void);

/**
 * @description: Clear exception information after a period of time.
 */
static void clear_int(void)
{
    char str[50] = "";
    strappend(str, ' ', 30);
    message(LEFT, WHITE, str);
}

/**
 * @description: The default exception handler.
 */
void ignoreIntBody(void)
{
    message(LEFT, RED, "Unknown interrupt");
    setTimeout(clear_int, 2000);
    throw;
}

/**
 * @description: The keyboardInterrupt handler.
 */
void keyboardInterrupt(void)
{
    message(LEFT, RED, "KeyboardInterrupt");
    setTimeout(clear_int, 2000);
    init8259A();
    disable_interrupt();
    setTimeout(enable_interrupt, 2000);
}